<?php 

Yii::import('zii.widgets.jui.CJuiWidget');

class FlashSlider extends CJuiWidget {

	public $width;
	
	public $height;
	
	public $htmlOptions;
	
	public $id = 'slider';
	
	public $items = array();
	
	public $baseUrl;
	
	public $scriptFile=array('jquery.flashSlider-1.0.min.js');
	
	public $cssFile=array('jquery.flashSlider.css');
	
	public function init(){
		$path=dirname(__FILE__).DIRECTORY_SEPARATOR.'assets';
        $this->baseUrl=Yii::app()->getAssetManager()->publish($path);
        $this->themeUrl	= $this->scriptUrl	= $this->baseUrl;
        Yii::app()->getClientScript()->registerCoreScript('jquery');
		Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id, implode("\n", $this->getRegisterScripts()));
        parent::init();
	}
	
	public function run(){
		$html = '<div id="'.$this->id.'" style="height:'.$this->height.';width:'.$this->width.';" class="'.$this->htmlOptions['class'].'"><ul>';
		foreach ($this->items as $key=>$play){
			$html .= '<li>
						<a href="'.$play['link'].'" target="'.$play['target'].'">
							<img height="'.$this->height.'" width="'.$this->width.'" src="'.$play['src'].'" alt="'.$play['title'].'" title="'.$play['title'].'"/>
						</a>
					</li>';
		}
		$html .= '</ul></div>';
		echo $html;
	}
	protected function getRegisterScripts(){
		$js		= array();
		$js[] = "silder_{$this->id} = $(document).ready(function(){jQuery('#{$this->id}').flashSlider({pause:4000});});";
		return $js;
	}
}

?>